package com.szxydb.dmp.admin.system.controller;

import com.szxydb.dmp.admin.category.model.Category;
import com.szxydb.dmp.admin.category.vo.CategoryTreeVo;
import com.szxydb.dmp.admin.system.model.SystemRole;
import com.szxydb.dmp.admin.system.request.SystemRoleSearchRequest;
import com.szxydb.dmp.admin.system.service.SystemRoleService;
import com.szxydb.dmp.common.CommonPage;
import com.szxydb.dmp.common.CommonResult;
import com.szxydb.dmp.common.PageParamRequest;
import com.szxydb.dmp.utils.CrmebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("api/admin/system/role")
@Api(tags = "设置--权限管理--身份管理")
public class SystemRoleController {

    @Autowired
    private SystemRoleService systemRoleService;

    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public CommonResult<List<SystemRole>> info(@RequestParam(value = "ids") String ids){
        List<SystemRole> systemRole = systemRoleService.getListInIds(CrmebUtil.stringToArray(ids));
        return CommonResult.success(systemRole);
    }

    @ApiOperation(value = "菜单")
    @RequestMapping(value = "/menu",method = RequestMethod.GET)
    public CommonResult<List<CategoryTreeVo>> menu(){
        List<CategoryTreeVo> categoryTreeVoList = systemRoleService.menu();
        return CommonResult.success(categoryTreeVoList);
    }

    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public CommonResult<CommonPage<SystemRole>> getList(@Validated SystemRoleSearchRequest request, @Validated PageParamRequest pageParamRequest){
        CommonPage<SystemRole> systemRoleCommonPage = CommonPage.restPage(systemRoleService.getList(request,pageParamRequest));
        return CommonResult.success(systemRoleCommonPage);
    }

}
